package jn.cdz.location.collect.controller;

import jn.cdz.location.collect.entity.Location;
import jn.cdz.location.collect.repository.LocationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 池辽
 * @Date 2019/11/8 17:53
 **/
@RequestMapping("location")
@RestController
public class LocationController {
    @Autowired
    private LocationRepository locationRepository;

    @RequestMapping(method = RequestMethod.POST)
    private void save(@RequestBody List<Location> locations) {
        locationRepository.saveAll(locations);
    }

    @RequestMapping(method = RequestMethod.GET)
    private List<Location> allLocation() {
        List<Location> all = locationRepository.findAll(Sort.by(Sort.Order.asc("id")));
        return all;
    }

}
